﻿	      <?php include("conn.php");
             mysql_query('SET NAMES UTF8'); 

	  

class MyPrizeBean
{
	public $num;
	public $ordersid;
	public $zongjia;
	public $jieguo;

	function __construct($num,$ordersid,$zongjia,$jieguo)
	{
		$this->num      = $num;
		$this->ordersid      = $ordersid;
		$this->zongjia      = $zongjia;
		$this->jieguo      = $jieguo;
	}
}


if($_REQUEST[shopid]!="")
{
$rert39=mysql_query("select *from shop where  shopid ='".$_REQUEST[shopid]."'");
$rowf9=mysql_fetch_array($rert39);
}
if($_REQUEST[goodsid]!="")
{
$rert30=mysql_query("select *from goods where  goodsid ='".$_REQUEST[goodsid]."'");
$rowf=mysql_fetch_array($rert30);

$price=$rowf[price];
}
else
{
$price=$_REQUEST[jine];
}
	$prize = array();
	
 if($_REQUEST[userid]!="")
 {         
 
$rert31=mysql_query("select *from shop where  shopid ='".$rowf[shopid]."'");
$rowf1=mysql_fetch_array($rert31);

$state=1;
if ($_REQUEST[addressid]!='') {
	$rert322=mysql_query("select *from address where  id='".$_REQUEST[addressid]."' and  userid ='".$_REQUEST[userid]."'");
}else{
	$rert322=mysql_query("select *from address where  state ='".$state."' and  userid ='".$_REQUEST[userid]."'");
}


$di=mysql_fetch_array($rert322);

	$address=$di[province].",".$di[city].",".$di[address].",".$di[name].",".$di[tel];
$state=0;
function build_order_no(){
	return date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
}
$numss=build_order_no();

// 是否购买运费险并计算商品总价 
if ($_REQUEST[buyFreightRisk]==1) {
	// 查找运费险
	$query = mysql_query("select freightRisk from xitong where id=1");
	$freightRisk = mysql_fetch_assoc($query);
	// 查找运费险 end
	$jiage=$_REQUEST[jiage]*$_REQUEST[addnum]+$rowf1[distribution_fee]+$freightRisk[freightRisk];
	$buyFreightRisk = 1;

}else{
	$jiage=$_REQUEST[jiage]*$_REQUEST[addnum]+$rowf1[distribution_fee];
	$buyFreightRisk = 0;
}
// 是否购买运费险并计算商品总价 end

$date=date("Y-m-d H:i:s");
	$str = preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $_REQUEST['ly']);//转义表情 （输入法表情输入时使用）
	$zhuan=addslashes($str);//转义

$srat=mysql_query("INSERT INTO goodsorders(numbers,totalprice,userid,address,state,addtime,shopid,buyFreightRisk) VALUES ('$numss','$jiage','$_REQUEST[userid]','$address','$state','$date','$rowf[shopid]','$buyFreightRisk')");

$dingid=mysql_insert_id();

// 调用信息推送接口
$url = "http://120.24.0.10/xzpf/api/jpush/jpush.php?state=".$state."&ordersid=".$dingid;
file_get_contents($url);
// 调用信息推送接口 end

$stat=2;
$srats=mysql_query("INSERT INTO car(userid,goodsid,goodsname,fTitle,sTitle,price,state,ordersid,number,shopid,goodsselect) VALUES ('$_REQUEST[userid]','$_REQUEST[goodsid]','$rowf[title]','$_REQUEST[fTitle]','$_REQUEST[sTitle]','$jiage','$stat','$dingid','$_REQUEST[addnum]','$rowf[shopid]','$_REQUEST[xuanxiang]')");
	if ($_REQUEST[addnum]!='') {
		$addnum=$_REQUEST[addnum];
	}else{
		$addnum=1;
	}
	$srat1=mysql_query("update goods set number=number-'".$addnum."' where goodsid='".$_REQUEST['goodsid']."'");
	$srat2=mysql_query("update goods set xiaoliang=xiaoliang+'".$addnum."' where goodsid='".$_REQUEST['goodsid']."'");
	//减少该商品规格的数量
	if ($_REQUEST[sTitle]!='') {
		$srat3=mysql_query("update goodsselect set number=number-'".$addnum."' where goodsid='".$_REQUEST['goodsid']."' and fTitle='".$_REQUEST[fTitle]."' and sTitle='".$_REQUEST[sTitle]."'");
	}else{
		$srat3=mysql_query("update goodsselect set number=number-'".$addnum."' where goodsid='".$_REQUEST['goodsid']."' and fTitle='".$_REQUEST[fTitle]."'");
	}
	if($rowf[number]==1)
	{
	$shu=0;
	$srat1=mysql_query("update goods set shangjia='".$shu."' where goodsid='".$_REQUEST['goodsid']."'");
	}
	

	      if($srat==true)
	     {
		  $der=100;
		  
		  }
	
		}
		 else
		  {
		   $der=300;
		  }

$prize[] = new MyPrizeBean($numss,$dingid,$jiage,$der);
echo json_encode($prize);


?>